package cn.bytecollege.user.controller;

import cn.bytecollege.common.entity.User;
import cn.bytecollege.user.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "UserUpdateController",value = "/user/updateUser")
public class UserUpdateController extends HttpServlet {
    private UserService userService = null;
    public UserUpdateController(){
        userService = new UserService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收表单请求
        String userNickname =request.getParameter("userNickname");
        String userPhonenumber = request.getParameter("userPhonenumber");
        String userGender = request.getParameter("userGender");
        String id = request.getParameter("userId");

//        HttpSession session = request.getSession();
//        User user= (User) session.getAttribute("user");

        Integer userId = Integer.valueOf(id);
        //封装
        User tempUser = new User();
        tempUser.setUserNickname(userNickname);
        tempUser.setUserPhonenumber(userPhonenumber);
        tempUser.setUserGender(userGender);
        tempUser.setUserId(userId);
        userService.userUpdateById(tempUser);
        response.sendRedirect("/user/userInformation");
    }
}
